﻿using System.Data.Entity.ModelConfiguration;
using CH.FourBoards.LagerWalti.Persistence.Entities;

namespace CH.FourBoards.LagerWalti.Persistence.Mapping
{
    internal class TransactionMap : EntityTypeConfiguration<Transaction>
    {
        internal TransactionMap()
        {
            #region Primary Key and Row Version

            HasKey(t => t.Id);

            // RowVersion for optimistic locking
            //Property(t => t.Version).IsRowVersion();

            #endregion

            #region Properties

            Property(t => t.Date).IsRequired();
            Property(t => t.TypeId).IsRequired();
            Property(t => t.ProductId).IsRequired();
            Property(t => t.Quantity).IsRequired();

            #endregion

            #region Relationships

            HasRequired(t => t.Type).WithMany().HasForeignKey(t => t.TypeId);
            HasRequired(t => t.Product).WithMany().HasForeignKey(t => t.ProductId);
            
            #endregion

        }
    }
}
